package com.system.queue.controller;
import com.system.queue.bean.DataBean;
import com.system.queue.bean.PageBean;
import com.system.queue.bean.ResultBean;
import com.system.queue.bean.TableBean;
import com.system.queue.domain.Patient;
import com.system.queue.domain.Queue;
import com.system.queue.query.QueueQuery;
import com.system.queue.service.QueueService;
import com.system.queue.vo.QueueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @className: QueueController
 * @description: TODO 类描述
 * @author: Kuangkeli
 * @date: 2023/11/27 18:56
 **/
@RestController
@RequestMapping("/queue")
public class QueueController {

    @Autowired
    private QueueService queueService;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Queue queue){
        return queueService.saveQueue(queue);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return queueService.removeQueueById(id);
    }

    @PutMapping("/update")
    public boolean updateHandle(@RequestBody Queue queue){
        return queueService.modifyQueue(queue);
    }

    @GetMapping("/get/{id}")
    public QueueVO getHandle(@PathVariable("id") int id){
        return queueService.getQueueById(id);
    }

    @GetMapping("/get/list")
    public @ResponseBody TableBean<QueueVO> getList(QueueQuery query){
        PageBean<QueueVO> pageBean = queueService.selectPage(query);
        List<QueueVO> queueVOList = pageBean.getResult();
        Long count = pageBean.getTotal();
        TableBean<QueueVO> tableBean = new TableBean<>();
        tableBean.setCode("00000");
        tableBean.setMsg("");
        DataBean<QueueVO> data = new DataBean<>();
        data.setList(queueVOList);
        data.setTotal(count);
        tableBean.setData(data);
        return tableBean;
    }

    @GetMapping("/calling/{id}")
    public @ResponseBody Patient calling(@PathVariable("id") int id){
        return  queueService.calling(id);
    }
}
